﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using MarketOnlineDTO;
using MySql.Data.MySqlClient;


namespace MarketOnlineDAO
{
    public class MonAnDAO:BaseDataProvider
    {
        MySqlCommand _cmd;


        public List<MonAnDTO> LayDanhSachMonAn()
        {
            _cmd = CreateMysqlCommand();
            _cmd.CommandText = "select * from MonAn";
            _cmd.CommandType = CommandType.Text;

            DataTable dt = new DataTable();

            dt = ExecuteSelectCommand(_cmd);

            if (dt.Rows.Count <= 0)
            {
                return null;
            }

            List<MonAnDTO> list = new List<MonAnDTO>();

            foreach (DataRow row in dt.Rows)
            {
                MonAnDTO dto = new MonAnDTO();
                dto.MaMonAn = int.Parse(row["MaMonAn"].ToString());
                dto.TenMonAn = row["TenMonAn"].ToString();
                dto.HinhAnh = row["HinhAnh"].ToString();
                
                list.Add(dto);
            }

            return list;
        }

    }
}
